package com.forlove.app.common.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.forlove.app.R;

/**
 * 邀请好友
 * Created by yjl on 2017/10/12.
 */

public class QyqToastTest extends Dialog {
    private Window mWindow;
    private Context mContext;
    /**
     * 进入动画是windowAnimation windowAnimation定义在style中.
     */
    protected int[] mAnimations = {R.style.QYQ_Dialog_Animation_Fly,
            R.style.QYQ_Dialog_Animation_Fade,
            R.style.QYQ_Toast_Animation_Fly,
            R.style.QYQ_Toast_Animation_Fade,
            R.style.QYQ_Dialog_Animation_FlyInFadeOut,
            R.style.QYQ_Dialog_Animation_FlyInFlyOut,
            R.style.QYQ_Toast_Animation_FlyInFlyOut,
            R.style.QYQ_Toast_Animation_FlyTopInFlyTopOut};

    public QyqToastTest(Context context) {
        super(context, R.style.FullScreenDialog);
        setContentView(R.layout.toast_error_message);
        mWindow = getWindow();
        mContext = context;
        mWindow.setWindowAnimations(mAnimations[AnimationType.TOAST_TOP_IN_FLY_TOP_OUT.getValue()]);
        mWindow.setGravity(Gravity.CENTER | Gravity.TOP);
        WindowManager.LayoutParams layoutParams = mWindow.getAttributes();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            mWindow.setDimAmount(0);
            // 低版本去除dim遮罩方法
        } else {
            layoutParams.dimAmount = 0.0f;
            mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        layoutParams.width = (int) (display.getWidth());
        mWindow.setAttributes(layoutParams);
        mWindow.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        // toast不获得焦点
        mWindow.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

    }


}
